package com.woniuxy.pxxt.controller;


import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
import com.woniuxy.pxxt.common.enums.UserTrainStatus;
import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.common.vo.FindTrainUserScheduleVo;
import com.woniuxy.pxxt.common.vo.train.TrainMsgVo;
import com.woniuxy.pxxt.dto.UserScoreDto;
import com.woniuxy.pxxt.entity.Train;
import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.service.TestService;
import com.woniuxy.pxxt.service.TrainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 培训项目的表(PxxtTrain)表控制层
 *
 * @author makejava
 * @since 2022-03-07 16:33:15
 */
@Api(value = "培训项目的表")
@RestController
@RequestMapping("/train")
@CrossOrigin
public class TrainController {
    @Autowired
    private TrainService trainService;

    @ApiOperation(value = "创建培训项目")
    @PostMapping("/createTrain/{trainImgName}/{trainImgUrl}")
    public Result createTrain(@PathVariable("trainImgName") String trainImgName,@PathVariable("trainImgUrl") String trainImgUrl,  @RequestBody Train train){
        return trainService.createTrain(trainImgName,trainImgUrl, train);
    }

    @ApiOperation(value = "查询培训项目")
    @PostMapping("/findTrain/{currentPage}/{pageSize}")
    public Result findTrain(@PathVariable("currentPage") Integer currentPage,
                            @PathVariable("pageSize") Integer pageSize,
                            @RequestBody Train train){
        return trainService.findTrain(currentPage,pageSize,train);
    }

    @ApiOperation(value = "根据id查询单个培训的所有信息")
    @GetMapping("/findTrainByIdEdit/{id}")
    public Result findTrainByIdEdit(@PathVariable("id") Integer id){
        return trainService.findTrainByIdEdit(id);
    }

    @ApiOperation(value = "更新方法")
    @PostMapping("/updateTrain/{trainImgName}/{trainImgUrl}")
    public Result updateTrain(@PathVariable("trainImgName") String trainImgName,@PathVariable("trainImgUrl") String trainImgUrl,  @RequestBody Train train){
        return trainService.updateTrain(trainImgName,trainImgUrl, train);
    }


    @ApiOperation(value = "获得前端的用户id和 培训id 为当前用户新增到课程中")
    @PostMapping("/addTrain/{userId}/{trainId}")
    public Result addTrain(@PathVariable Integer userId,
                           @PathVariable Integer trainId) {
        return trainService.addUserToTrain(userId, trainId);
    }

    @ApiOperation(value = "通过培训的id 查询下面所有的培训人员 进行分页")
    @GetMapping("/findTrainUser/{trainId}/{currentPage}/{pageSize}")
    public Result findTrainUser(@PathVariable Integer trainId,
                                @PathVariable Integer currentPage,
                                @PathVariable Integer pageSize) {
        return trainService.findTrainUser(trainId, currentPage, pageSize);
    }

    @ApiOperation(value = "通过培训的id 查询学员的进度 ")
    @PostMapping("/findTrainUserSchedule/{currentPage}/{pageSize}")
    public Result findTrainUserSchedule(@PathVariable Integer currentPage,
                                        @PathVariable Integer pageSize,
                                        @RequestBody FindTrainUserScheduleVo findTrainUserScheduleVo) {
        return trainService.findTrainUserSchedule(currentPage, pageSize, findTrainUserScheduleVo);
    }

    @ApiOperation(value = "通过培训的id 查询学员的学习成绩分数 ")
    @PostMapping("/findTrainUserScore/{currentPage}/{pageSize}")
    public Result findTrainUserScore(@PathVariable Integer currentPage,
                                     @PathVariable Integer pageSize,
                                     @RequestBody FindTrainUserScheduleVo findTrainUserScheduleVo) {
        return trainService.findTrainUserScore(currentPage, pageSize, findTrainUserScheduleVo);
    }

    @ApiOperation(value = "通过用户培训的ids  设置该学员的培训状态 ")
    @PostMapping("/verifyUser/{status}")
    public Result verifyUser(@RequestBody UserScoreDto userScoreDto,
                             @PathVariable Integer status) {

        return trainService.setUserStatus(userScoreDto,status);
    }


    @ApiOperation(value = "通过id删除培训项目")
    @DeleteMapping("/delTrainById/{trainId}")
    public Result delTrainById(@PathVariable("trainId") Integer id) {
        return trainService.delTrainById(id);
    }

    @ApiOperation(value = "通过培训id获取培训项目的所有信息")
    @GetMapping("/findTrainById/{trainId}")
    public Result findTrainById(@PathVariable("trainId") Integer id) {
        return trainService.findTrainById(id);
    }

    @ApiOperation(value = "返回所有的培训状态")
    @GetMapping("/findAllTrainIsSuccess")
    public Result findAllTrainIsSuccess (){
        return Result.ok(UserTrainStatus.getStatusList());
    }


    @ApiOperation(value = "返回所有的培训对应内容")
    @PostMapping("/findAllTrain")
    public Result findAllTrain (@RequestBody TrainMsgVo trainMsgVo){
        return trainService.findAllTrain(trainMsgVo);
    }


}

